package control;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.service.TheaterService;
import model.vo.theater.PlayRoomVO;
import model.vo.theater.TheaterVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class TheaterController  extends MultiActionController{
	/**
	 * Spring DI 사용
	 */
	
	private TheaterService theaterService;
	public TheaterController() {
		super();
		// TODO Auto-generated constructor stub
	}

	public TheaterController(TheaterService theaterService){
		this.theaterService=theaterService;
	}	
	
	/**
	 * 극장 - 지역별 영화관정보 (초기화면) 
	 * 받아오는 지역(local)에 따라서 한페이지에 다양한 정보 출력
	 */
	public ModelAndView loadLocalInfo(HttpServletRequest request, HttpServletResponse response){
		ArrayList<TheaterVO> tList=new ArrayList<TheaterVO>();
		HashMap map=new HashMap();
		tList=theaterService.loadTheaterListByLocalNo(1);
		map.put("tList", tList);
		map.put("loc", "서울");
		request.setAttribute("map",map);
		System.out.println("loadLocalInfo join.."+map);
		return new ModelAndView("theaterMain");
	}
	/**
	 * 클라이언트에서 지역 no 를 int 값으로 받아서
	 * 영화관 리스트를 클라언트에 반환 시킴
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView loadTheaterList(HttpServletRequest request, HttpServletResponse response){
		ArrayList<TheaterVO> tList=new ArrayList<TheaterVO>();
		int locNo=Integer.parseInt(request.getParameter("loc"));
		tList=theaterService.loadTheaterListByLocalNo(locNo);
		System.out.println("loadTheaterList join.."+tList);
		return new ModelAndView("JsonView","tList",tList);
	}
	/**
	 * 클라이언트에서 영화관 no 를 int 값으로 받아서
	 * 영화관 상세 정보를 클라이언트에 반환 시킴
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView loadTheaterInfo(HttpServletRequest request, HttpServletResponse response){
		ArrayList<PlayRoomVO> pList=new ArrayList<PlayRoomVO>();
		int theater_no=Integer.parseInt(request.getParameter("tNo"));
		pList=theaterService.loadTheaterInfoByTheaterlNo(theater_no);
		System.out.println("loadTheaterInfo.."+pList);
		return new ModelAndView("JsonView","pList",pList);
	}
}








